<style>
    #container{
        padding: 0px;
        border-radius:0px;
        border-width:0px;
    }
</style>
<form class="layui-form seller-alone-form" action="" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>选择分类：</label>
        <div class="layui-input-inline seller-inline-5">
            <select name="type_id" id="type" lay-verify="required" style="z-index: 5">
                <option value="">请选择文章分类</option>
                {volist name='list' id='vo'}
                <option value="{$vo.id}">{$vo.type_name}</option>
                {/volist}
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>文章标题：</label>
        <div class="layui-input-inline seller-inline-5">
            <input type="text" name="title" required  lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>封面图：</label>
        <div class="layui-input-inline seller-inline-5">
            {ZlServer:image id='img' name='cover' required lay-verify='required'/}
        </div>
    </div>

    <div class="layui-form-item layui-form-text" >
        <label class="layui-form-label"><i class="required-color">*</i>文章内容：</label>
        <div class="layui-input-block" style="z-index: 1">
            <textarea id="container" name="content" style="width:100%;height:300px;" type="text/plain" required  lay-verify="required" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item" style="margin: 20px;">
        <label class="layui-form-label">是否发布：</label>
        <div class="layui-input-block">
            <input type="radio" name="is_pub" value="1" title="立即发布">
            <input type="radio" name="is_pub" value="2" title="暂不发布" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>排序：</label>
        <div class="layui-input-block seller-inline-2">
            <input type="text" name="sort" required  lay-verify="required" value="100" placeholder="从小到大排列" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            {:zlserverToken()}
            <button id="article_add_save" type="button" class="layui-btn" lay-submit lay-filter="save">保存</button>
        </div>
    </div>

</form>

<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>

<script src="../layui/layui.js"></script>
<script> 
    layui.use(['form'], function () {
        var form = layui.form;
        form.render();
 
        //保存用户
        form.on('submit(save)', function(data){
            formData = data.field;
            if(!formData){
                layer.msg('请先完善数据', {time: 1300});
                return false;
            }
 
            $("#article_add_save").addClass("layui-btn-disabled");
            $('#article_add_save').attr("disabled", true);

            $.ajax({
                type: 'post',
                url: '{:url("Article/add")}',
                data: formData,
                dataType: 'json',
                success: function (e) { 
                    if(e.status === true){ 
                        layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,id: 'layerDemoAuto'
                            ,content: '<div style="padding: 20px 100px;">'+ e.msg +'</div>'
                            ,btn: '关闭'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0.3 //显示遮罩
                            ,yes: function(){
                                parent.layui.admin.events.changeTabAndRefresh('/manage/article/index.html');
                            },close: function() {
                                console.log('close');
                            },end: function() {
                                parent.layui.admin.events.changeTabAndRefresh('/manage/article/index.html');
                            }
                        });
                    }else{ 
                        $("#article_add_save").removeClass("layui-btn-disabled");
                        $('#article_add_save').removeAttr("disabled");
                        layer.msg(e.msg, {time: 1300});
                    }
                }
            });
            return false;
        });
    });
</script>
